﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Data.EntityClient;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;
using System.Xml.Serialization;


namespace FPP.Models
{
    public partial class PoolType : EntityObject
    {
        #region Primitive Properties

        public virtual int Id
        {
            get;
            set;
        }

        public virtual string Name
        {
            get;
            set;
        }

        [Display(Name = "Roster Size")]
        public virtual string NumOfPeople
        {
            get;
            set;
        }

        public virtual string NumOfAlts
        {
            get;
            set;
        }

        [Display(Name = "Win Rule")]
        public virtual string WinRule
        {
            get;
            set;
        }

        public virtual string WinMultiplier
        {
            get;
            set;
        }

        [Display(Name = "Date Start")]
        public virtual string DateStart
        {
            get;
            set;
        }

        [Display(Name = "Date End")]
        public virtual string DateEnd
        {
            get;
            set;
        }

        #endregion

        #region Class Properties
        public bool OpenGame()
        {
            var compareDate = DateTime.Parse(DateStart);
            return (compareDate < DateTime.Now);

        }
        public bool ActiveGame()
        {
            var compareDate = DateTime.Parse(DateStart);
            var endDate = DateTime.Parse(DateEnd);
            return (compareDate < DateTime.Now && endDate > DateTime.Now);

        }
        public bool ClosedGame()
        {
            var compareDate = DateTime.Parse(DateEnd);
            return (compareDate < DateTime.Now);

        }

        #endregion

        #region Associative Properties
        public List<User> Users
        {
            get
            {

                List<User> oUsers = new List<User>();

                using (fppEntities context = new fppEntities(FPP.Controllers.DataAccess.ffpCString))
                {
                    var q = from u in context.Users
                            join p in context.Pools on u.Id equals p.UserId
                            where p.PoolTypeId == this.Id
                            select u;

                    foreach (User u in q)
                    {
                        if(!oUsers.Contains(u))
                            oUsers.Add(u);
                    }

                }

                return oUsers;
            }
        }
        #endregion
    }
}